﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Prologis.ShifterNT.Unity;
using System.IO;
using Prologis.ShifterNT.Datasource;
using Prologis.ShifterNT.Datasink;
using Microsoft.Practices.Unity.Configuration;
using System.Configuration;

namespace Prologis.ShifterNT.Testapp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            label1.Text = "---------";
            comboBoxConfig.Text = comboBoxConfig.Items[0].ToString();
            comboBoxFileldefs.Text = comboBoxFileldefs.Items[0].ToString();
            comboBoxDatafile.Text = comboBoxDatafile.Items[0].ToString();

        }



        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string selectedConfig = comboBoxConfig.SelectedItem.ToString();
            string selectedFielddef = comboBoxFileldefs.SelectedItem.ToString();
            string selectedData = comboBoxDatafile.SelectedItem.ToString();

            Prologis.ShifterNT.AppenderSkeleton append = Builder.BuildShifter(selectedConfig);
            append.DataSource.Tokenizer.FieldConfigPath = selectedFielddef; 
            LargeFileSource dataSource = append.DataSource as  LargeFileSource;
            dataSource.File = selectedData;

            MemorySink dataSink = append.DataSink as  MemorySink;
            bool result = append.Execute();

            richTextBox1.Text = "";
            richTextBox1.Text = dataSink.Imorted[0];
            label1.Text = result ? "OK" : "ERROR";

            string s = "";


        }

      

        private void button3_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string selectedConfig = comboBoxConfig.SelectedItem.ToString();
            string selectedFielddef = comboBoxFileldefs.SelectedItem.ToString();
            string selectedData = comboBoxDatafile.SelectedItem.ToString();

            Prologis.ShifterNT.AppenderSkeleton append = Builder.BuildShifter(selectedConfig);
            append.DataSource.Tokenizer.FieldConfigPath = selectedFielddef;
            LargeFileSource dataSource = append.DataSource as LargeFileSource;
            dataSource.File = selectedData;
            INestedDataSource nested = new ApplikationDataSource();
            dataSource.AddNestedDataSource(nested);

            MemorySink dataSink = append.DataSink as MemorySink;
            bool result = append.Execute();

            richTextBox1.Text = "";
            richTextBox1.Text = dataSink.Imorted[0];
            label1.Text = result ? "OK" : "ERROR";
            string s = "";
        }

      


    }
}
